<template>
  <Model
    :title="row.edit ? '编辑' : '添加'"
    :width="800"
    :show="show"
    @confirm="confirm"
    @cancel="cancel"
  >
    <Form slot="form">
      <FormDoubleItem :labels="['年度', '时间']">
        <a-input
            slot="left"
            v-model="row.year"
            placeholder="请输入年度"
        />
        <a-date-picker
          :default-value="row.time"
          v-model="row.time"
          format="yyyy-MM-DD hh:mm:ss"
          show-time
          slot="right"
        />
      </FormDoubleItem>

      <FormDoubleItem :labels="['企业', '举办地']">
        <a-select
            slot="left"
            show-search
            placeholder="请选择"
            option-filter-prop="children"
            style="width: 100%"
            v-model="row.company"
        >
          <a-select-option
              v-for="item in AllBase"
              :key="item.name"
              :value="item.id"
          >
            {{ item.name }}
          </a-select-option>
        </a-select>


        <a-input slot="right" v-model="row.place" placeholder="请输入举办地" />
      </FormDoubleItem>

      <FormDoubleItem :labels="['所需职务', '所需人数']">
        <a-input slot="left" v-model="row.needJob" placeholder="职务" />
        <a-input slot="right" v-model="row.number" placeholder="人数" />
      </FormDoubleItem>
      <FormDoubleItem :labels="['宣讲人', '宣讲人岗位']">
        <a-input slot="left" v-model="row.talking" placeholder="姓名" />
        <a-input slot="right" v-model="row.apply" placeholder="宣讲人岗位" />
      </FormDoubleItem>
      <FormDoubleItem :labels="['宣讲会人数']">
        <a-input
          slot="left"
          v-model="row.talkingMember"
          placeholder="实际录用人数"
      /></FormDoubleItem>

      <FormDoubleItem :labels="['系负责人', '是否显示']">
        <a-input slot="left" v-model="row.leader" placeholder="系负责人" />
        <a-select
          slot="right"
          show-search
          v-model="row.status"
          option-filter-prop="children"
          style="width: 100%"
          @change="TypeChanges"
          placeholder="是否显示"
        >
          <a-select-option value="0">不显示</a-select-option>
          <a-select-option value="1">显示</a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['实际录用人数', '所需专业']">
        <a-input
          slot="left"
          v-model="row.factMember"
          placeholder="实际录用人数"
        />
        <a-select
          slot="right"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.profession"
          @change="(e) => changeValue(e, 'profession')"
        >
          <a-select-option
            v-for="item in systemInfo"
            :key="item.name"
            :value="item.name"
          >
            {{ item.name }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
    </Form>
  </Model>
</template>

<script>
import Model from "@/components/common/model/Model";
import Form from "@/components/common/form/Form";
import FormItem from "@/components/common/form/formItem/FormItem";
import FormLenItem from "components/common/form/formItem/FormLenItem";
import FormDoubleItem from "components/common/form/formDoubleItem/FormDoubleItem";

import { getSystem } from "@/network/Info/BaseInfo";
import { getAllBase } from "@/network/Base/b-job"
import { check, newsType, newsStatus, years } from "@/assets/data/other";
import moment from "moment";
export default {
  components: {
    Model,
    Form,
    FormDoubleItem,
    FormLenItem,
    FormItem,
    years,
  },
  props: {
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    show: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {
      AllBase:[],
      check,
      newsType,
      newsStatus,
      moment,
      years,
      systemInfo: [{ id: 1, name: 0 }],
    };
  },
  created() {
    this.init();
  },
  methods: {
    async init() {
      const companyData = await getAllBase();
      const data = await getSystem();
      if( data.msg ) {
        this.systemInfo = data.data[0].data;
      }
      if( companyData.msg ){
        this.AllBase = companyData.data;
      }
    },
    beforeUpload(file) {
      this.row.file = [file];
      return false;
    },
    changeValue(value, key) {
      this.row[key] = value;
      console.log(this.row[key]);
    },
    handleRemove(file) {
      const index = this.row.file.indexOf(file);
      const newFileList = this.row.file.slice();
      newFileList.splice(index, 1);
      this.row.file = newFileList;
    },
    confirm() {
      const row = this.row;
      delete this.row.companyName;
      row.check = 0;
      row.status == "显示"
        ? (row.status = 1)
        : row.status == "不显示"
        ? (row.status = 2)
        : row.status;
      this.row.time = moment(this.row.time).format("yyyy-MM-DD HH:mm:ss");
      console.log( this.row.time );
      this.systemInfo.forEach((item) => {
        console.log(row.profession);
        if (item.name === row.profession) {
          row.profession = item.id;
        }
      });
      this.$emit("confirm", {
        ...row,
      });
      this.row = {};
    },
    cancel() {
      this.$emit("cancel");
    },
    Changes(value) {
      this.$forceUpdate();
    },
    TypeChanges(value) {
      this.$forceUpdate();
    },
  },
};
</script>

<style lang="less" scoped>
.t-form {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-items: center;
  padding-right: 30px;
  .ant-btn {
    width: 145.5px !important;
  }
}
</style>
